import math
import matplotlib.pyplot as plt

def sigmoid(x):
  return 1 / (1 + math.exp(-x))

def tanh(x):
  return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))

x = [x/float(100) for x in range(-1000,1000,40)]
y_1 = [sigmoid(a) for a in x]
y_2 = [tanh(a) for a in x]

fig = plt.figure()
line_tanh,= plt.plot(x,y_2,'go-', label='tanh')
line_sig,= plt.plot(x,y_1,'rv-', label='sigmoid')
plt.legend([line_sig,line_tanh],['sigmoid','tanh'])
plt.xlabel("x", fontsize=16)
plt.ylabel("f(x)", fontsize=16)
plt.ylim(-1,1)
plt.show()
